package cn.star.jots.film.controller;

import cn.star.jots.base.response.JsonResult;
import cn.star.jots.film.pojo.dto.FilmQuery;
import cn.star.jots.film.pojo.dto.FilmSaveParam;
import cn.star.jots.film.pojo.dto.FilmSubjectQuery;
import cn.star.jots.film.pojo.dto.UserFilmQuery;
import cn.star.jots.film.pojo.vo.FilmDataVO;
import cn.star.jots.film.pojo.vo.FilmVO;
import cn.star.jots.film.service.FilmService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/v1/film")
@Api(tags = "电影管理")
@Slf4j
public class FilmController {

    @Autowired
    FilmService filmService;

    @GetMapping("/select")
    @ApiOperation(value = "查询电影信息")
    public JsonResult selectAll(FilmQuery filmQuery) {
        log.info("查询电影信息:filmQuery={}", filmQuery);
        List<FilmVO> list = filmService.selectAll(filmQuery);
        return JsonResult.ok(list);
    }

    @GetMapping("/select/subject")
    @ApiOperation(value = "查询非专题里的电影信息")
    public JsonResult selectSubjectFilm(FilmSubjectQuery filmSubjectQuery) {
        log.info("查询专题的电影信息:filmSubjectQuery={}", filmSubjectQuery);
        List<FilmVO> list = filmService.selectSubjectFilm(filmSubjectQuery);
        return JsonResult.ok(list);
    }

    @PostMapping("/save")
    @ApiOperation(value = "保存电影信息")
    public JsonResult save(FilmSaveParam filmSaveParam) {
        log.info("保存电影信息:filmSaveParam={}", filmSaveParam);
        filmService.save(filmSaveParam);
        Long filmId = filmService.save(filmSaveParam);
        log.info("保存电影信息成功,电影id:{}", filmId);
        return JsonResult.ok(filmId);
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除电影信息")
    public JsonResult delete(@PathVariable Long id) {
        log.info("删除电影信息:id={}", id);
        filmService.deleteFilm(id);
        return JsonResult.ok();
    }

    @PutMapping("/update")
    @ApiOperation(value = "更新电影信息")
    public JsonResult update(FilmSaveParam filmSaveParam) {
        log.info("更新电影信息:filmSaveParam={}", filmSaveParam);
        filmService.update(filmSaveParam);
        return JsonResult.ok();
    }

    @PutMapping("/update/status/{id}/{status}")
    @ApiOperation(value = "更新电影上架状态")
    public JsonResult updateStatus(@PathVariable Long id, @PathVariable String status) {
        log.info("更新电影上架状态:id={},status={}", id, status);
        filmService.updateStatus(id, status);
        return JsonResult.ok();
    }

    @GetMapping("/select/userFilm")
    @ApiOperation(value = "查询用户电影信息")
    public JsonResult selectUserFilm(UserFilmQuery userFilmQuery) {
        log.info("查询用户电影信息:userFilmQuery={}", userFilmQuery);
        List<FilmVO> list = filmService.selectUserFilm(userFilmQuery);
        return JsonResult.ok(list);
    }

    @GetMapping("/selectData")
    @ApiOperation(value = "查询电影数据")
    public JsonResult selectData() {
        log.info("查询电影数据");
        FilmDataVO vo = filmService.selectData();
        return JsonResult.ok(vo);
    }

}
